home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / KMAGV3.ZIP / XMSEXAM.PAS < prev   
Pascal/Delphi Source File  |  1996-01-11  |  6KB  |  194 lines

  1. {XMSEXAM.PAS / EXAMPLE FOR FADE XMS ROUTINES}
  2. {WRITING BY THE KING IN 01/02/96            }
  3. Uses Crt;
  4.  
  5. Type
  6. {This is a struct for move block via XMS to Conventional Memory}
  7. {Or Conventional Memory To XMS}
  8.  
  9.     XmsMoveStruct = Record
  10.         Length  : LongInt;   {The LENGTH of the block in BYTES}
  11.         SHandle : Word;      {Source Handle}
  12.         SOffset : Longint;   {Source Offset}
  13.         DHandle : Word;      {Destinaton Handle}
  14.         DOffset : Longint;   {Destinaton Offset}
  15.     End;
  16. Var
  17.     XMove : XmsMoveStruct;   {An Xms Move Stuct , for moving}
  18.     Xms_Address : LongInt;   {The Address to the software interrupt}
  19.     Handle : Word;           {Handle for allocate memory}
  20.  
  21. {-----------------------------------------------}
  22. {       Checking If XMS Program Installed       }
  23. {-----------------------------------------------}
  24.  
  25. Function XMSInstalled:Boolean;
  26. var
  27.     Installed : Boolean;
  28. Begin
  29. Asm
  30.     Mov ax,4300h    {Function Ax=4300, Int 2Fh , Checking XMS INSTALLED}
  31.     Int 2fh
  32.     Cmp al,80h      {If Al=80h mean that XMS found.}
  33.     je @found
  34.     Mov Installed,0 {Else Installed = False}
  35.     Jmp @Exit       {Exit}
  36. @Found:
  37.     Mov Installed,1 {In Case XMS INSTALLED , Installed = True}
  38. @Exit:
  39. End;
  40.     XmsInstalled := Installed;  {Return to function result}
  41. End;
  42.  
  43. {-----------------------------------------------}
  44. {     Get the XMS software intterupt handle.    }
  45. {-----------------------------------------------}
  46.  
  47. Procedure Get_XMS_Address;
  48. Begin
  49.     Asm
  50.         Mov Ax,4310h     {Function Ax=4310h , Int 2Fh , Get Handle Of Xms}
  51.         Int 2fh          {Interrupt.}
  52.         Mov Word Ptr [Xms_Address+2],Es  {Moving to The Hi Word Of Handle
  53.                                           The Hi Word of the Interrupt.}
  54.         mov word ptr [Xms_Address],Bx    {Moving to The Low Word Of Handle
  55.                                           The Low Word of the Interrupt.}
  56.     End;
  57. End;
  58.  
  59. {-----------------------------------------------}
  60. {            Allocate Memory to handle.         }
  61. {-----------------------------------------------}
  62. Function AllocateMemory(Var Handle : Word;AllocK:Word) : Boolean;Assembler;
  63. asm
  64.     mov ah,09h            {Function Ah=09 , Allocate Memory}
  65.     Mov Dx,AllocK         {Dx=the size to allocate in KB}
  66.     Call Xms_Address      {Calling the interrupt}
  67.     Les Di,Handle         {[Es:Di] = Handle}
  68.     Mov [Es:Di],Dx        {[Es:Di] = Allocated Handle}
  69. End;
  70.  
  71. {-----------------------------------------------}
  72. {            Free Memory From handle.           }
  73. {-----------------------------------------------}
  74.  
  75. Function FreeMemory(Handle : Word):Boolean;assembler;
  76. asm
  77.     Mov Ah,0Ah        {Function Ah=0Ah , Free Memory}
  78.     Mov Dx,Handle     {Dx=Handle}
  79.     Call Xms_Address  {Calling Intterupt}
  80. end;
  81.  
  82. {-----------------------------------------------}
  83. {    Reallocated Memory Without losing data     }
  84. {-----------------------------------------------}
  85.  
  86. Function ReAllocMemory(Handle:Word;NewSize:Word):Boolean;Assembler;
  87. Asm
  88.     Mov Ah,0Fh        {Function Ah=0Fh , Reallocate memory}
  89.     Mov Bx,NewSize    {Bx = New Size}
  90.     Mov Dx,Handle     {Dx = Handle}
  91.     Call Xms_Address  {Calling Interrupt}
  92. End;
  93.  
  94.  
  95. {-----------------------------------------------}
  96. { Moving Memory Form Convertional memory To XMS }
  97. {-----------------------------------------------}
  98.  
  99. Function   RealToXms(Size:LongInt;Source:LongInt;DHandle:Word) : Boolean;
  100. Var
  101.     Ok : Boolean;
  102. Begin
  103.     {Building Struct}
  104.     XMove.Length  := Size;
  105.     XMove.Shandle := 0;
  106.     XMove.SOffset := Source;
  107.     XMove.Dhandle := Dhandle;
  108.     XMove.DOffset := 0;
  109.     Asm
  110.         Mov Ah,0Bh       {Function Ah=0Bh , Moving Memory}
  111.         Lea SI,XMove     {[Ds:Si] = XMove}
  112.         Call Xms_Address {Calling Interrupt}
  113.         Mov Ok,Al
  114.     End;
  115.     RealToXms := Ok;
  116. End;
  117.  
  118. {-----------------------------------------------}
  119. { Moving Memory Form XMS To Convertional memory }
  120. {-----------------------------------------------}
  121.  
  122. Function   XmsToReal(Size:LongInt;SHandle:Word;Dest:LongInt) : Boolean;
  123. Var
  124.     Ok : Boolean;
  125. Begin
  126.     XMove.Length  := Size;
  127.     XMove.Shandle := SHandle;
  128.     XMove.SOffset := 0;
  129.     XMove.Dhandle := 0;
  130.     XMove.DOffset := Dest;
  131.     Asm
  132.         Mov Ah,0Bh             {Function Ah=0Bh , Moving Memory}
  133.         Lea SI,XMove           {[Ds:Si] = XMove}
  134.         Call Xms_Address       {Calling Interrupt}
  135.         Mov Ok,Al
  136.     End;
  137.     XmsToReal := Ok;
  138. End;
  139.  
  140. {---------------------------------------------}
  141. {           Return Free XMS Memory            }
  142. {---------------------------------------------}
  143.  
  144. Function FreeMem : Word;Assembler;
  145. Asm
  146.     Mov Ah,8h            {Ah = 08h , Return Free Memory}
  147.     Call Xms_address     {Calling Interrupt}
  148. End;
  149.  
  150. Begin
  151.     If XMSINSTALLED Then
  152.     Begin
  153.         Writeln('XMS Found.');
  154.         Get_XMS_Address;
  155.         Writeln('Total free memory = ',FreeMem,'Kb');
  156.         Writeln;
  157.         Writeln('Press Enter to try to Move the screen memory to XMS');
  158.         Readln;
  159.  
  160.         If Not AllocateMemory(Handle,8) Then
  161.         Begin
  162.             Writeln('Cant Allocate 8k of memory in XMS');
  163.             Halt;
  164.         End;
  165.         If Not RealToXms(8000,LongInt(Ptr($0b800,0)),Handle) Then
  166.         Begin
  167.             Writeln('Cant Move From Convertsional memory to XMS.');
  168.             Halt;
  169.         End;
  170.         ClrScr;
  171.         Writeln('Memory Moved Successfull..');
  172.         Writeln('Press Enter To Restore the memory screen from XMS');
  173.         Readln;
  174.         If Not XmsToReal(8000,Handle,LongInt(Ptr($0b800,0))) Then
  175.         Begin
  176.             Writeln('Cant Move From XMS To Convertsiomal memory.');
  177.             Halt;
  178.         End;
  179.         If Not FreeMemory(Handle) Then
  180.         Begin
  181.             Writeln('Cant Free Memory...');
  182.             Halt;
  183.         End;
  184.         Gotoxy(1,24);
  185.         Writeln('Well everything is ok ! :) Press enter to return.');
  186.         readln;
  187.  
  188.     End
  189.     Else
  190.         Writeln('XMS Not Found.');
  191. End.
  192. #include "kmagunit.c"
  193.  
  194. virtualscreen